package com.imcode.exceptiondemo;

import java.io.FileNotFoundException;

public class ExceptionDemo02 {

    public static void main(String[] args) throws FileNotFoundException, ClassNotFoundException {
        // 调用一个有异常声明的方法
        test01();
        test02();
        test03();
    }

//    public static void main(String[] args) throws Exception {
//        test01();
//        test02();
//    }

    /**
     * 声明了一个异常，表示调用该方法的时候，可能会抛出FileNotFoundException
     *
     * @throws FileNotFoundException
     */
    public static void test01() throws FileNotFoundException {
        System.out.println("抛出异常");
        throw new FileNotFoundException("文件找不到");
    }

    public static void test02() throws ClassNotFoundException {
        throw new ClassNotFoundException();
    }

    /**
     * 运行期异常 类型转换异常
     * @throws ClassCastException
     */
    public static void test03() throws ClassCastException {
        // 运行期异常在编译阶段可以不处理
        throw new ClassCastException("类型转换异常");
    }
}
